package com.tianxiao.faas.application.web.corner;

import com.tianxiao.faas.api.param.corner.SearchHotResult;
import com.tianxiao.faas.api.param.corner.SearchHotSaveParam;
import com.tianxiao.faas.biz.service.corner.SearchHotService;
import com.tianxiao.faas.common.access.Access;
import com.tianxiao.faas.common.result.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/admin/search/hot/")
public class SearchHotAdminController {

    @Resource
    private SearchHotService searchHotService;


    @RequestMapping(value = "/save")
    @Access(access = {"admin"})
    public Result<Boolean> save(@RequestBody SearchHotSaveParam param) {
        searchHotService.save(param);
        return Result.builder().data(true).success(true);
    }

    @RequestMapping(value = "/scene/list")
    @Access(access = {"admin"})
    public Result<List<SearchHotSaveParam>> sceneList() {
        Integer count = 15;
        List<SearchHotResult> results = searchHotService.list(2, count);
        return Result.builder().data(results).success(true);
    }

    @RequestMapping(value = "/shop/list")
    @Access(access = {"admin"})
    public Result<List<SearchHotSaveParam>> shopList() {
        Integer count = 15;
        List<SearchHotResult> results = searchHotService.list(1, count);
        return Result.builder().data(results).success(true);
    }

    @RequestMapping(value = "/delete")
    @Access(access = {"admin"})
    public Result<Boolean> delete(Long id) {
        searchHotService.delete(id);
        return Result.builder().data(true).success(true);
    }
}
